import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';

import 'kb_bytedance_attribution_platform_interface.dart';

/// An implementation of [KbBytedanceAttributionPlatform] that uses method channels.
class MethodChannelKbBytedanceAttribution
    extends KbBytedanceAttributionPlatform {
  /// The method channel used to interact with the native platform.
  @visibleForTesting
  final methodChannel = const MethodChannel('kb_bytedance_attribution');

  @override
  Future<String?> getPlatformVersion() async {
    final version =
        await methodChannel.invokeMethod<String>('getPlatformVersion');
    return version;
  }

  @override
  Future<void> convertInit() async {
    return await methodChannel.invokeMethod('convertInit');
  }

  @override
  Future<void> sendLaunchEvent() async {
    return await methodChannel.invokeMethod('sendLaunchEvent');
  }

  @override
  Future<void> onEventV3(
      {required String eventName,
      required Map<String, dynamic> extraParams}) async {
    return await methodChannel.invokeMethod('onEventV3', {
      'eventName': eventName,
      'extraParams': extraParams,
    });
  }

  @override
  Future<void> onEventRegister(
      {required String registerMethod, required bool isSuccess}) async {
    return await methodChannel.invokeMethod('onEventRegister', {
      'registerMethod': registerMethod,
      'isSuccess': isSuccess,
    });
  }

  @override
  Future<void> onEventPurchase({
    required String contentType,
    required String contentName,
    required String contentId,
    required int contentNumber,
    required String paymentChannel,
    required String currency,
    required bool isSuccess,
    required int currencyAmount,
  }) async {
    return await methodChannel.invokeMethod('onEventPurchase', {
      'contentType': contentType,
      'contentName': contentName,
      'contentId': contentId,
      'contentNumber': contentNumber,
      'paymentChannel': paymentChannel,
      'currency': currency,
      'isSuccess': isSuccess,
      'currencyAmount': currencyAmount,
    });
  }

  ///===============iOS方法
  @override
  Future<void> iOSRegisterWithOptionalData({
    String? userUniqueId,
  }) async {
    return await methodChannel.invokeMethod(
        'registerWithOptionalData', userUniqueId);
  }

  @override
  Future<void> iOSEventRegister({
    Map<String, dynamic>? params,
  }) async {
    return await methodChannel.invokeMethod('eventRegister', params);
  }

  @override
  Future<void> iOSEventStayTime({
    Map<String, dynamic>? params,
  }) async {
    return await methodChannel.invokeMethod('eventStayTime', params);
  }

  @override
  Future<void> iOSEventPurchase({
    Map<String, dynamic>? params,
  }) async {
    return await methodChannel.invokeMethod('eventPurchase', params);
  }

  @override
  Future<void> iOSEventGameAddiction({
    Map<String, dynamic>? params,
  }) async {
    return await methodChannel.invokeMethod('eventGameAddiction', params);
  }

  @override
  Future<void> iOSEventCustom({
    required String eventName,
    Map<String, dynamic>? params,
  }) async {
    return await methodChannel.invokeMethod(
        'eventCustom', {'eventName': eventName, 'params': params});
  }

  @override
  Future<void> iOSEnableIdfa({
    required bool enable,
  })async {
    return await methodChannel.invokeMethod('enableIdfa', enable);
  }

  @override
  Future<String?> iOSGetClickId() {
    throw UnimplementedError('iOSGetClickId() has not been implemented.');
  }
  
}
